package strategy.browser;

import strategy.Node;

import java.util.LinkedList;
import java.util.List;

public class BFSTreeBrowser implements TreeBrowser {

    @Override
    public void browse(Node root, Node.INodeAction nodeAction) {
        LinkedList<Node> queue = new LinkedList<Node>();
        queue.add(root);

        while (!queue.isEmpty()) {
            Node node = queue.remove(0);
            nodeAction.doAction(node);

            List<Node> children = node.getChildren();
            for (Node child : children) {
                queue.addLast(child);
            }
        }
    }
}
